home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / gamekit-1 / GKActorManager.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  50 lines

  1.  
  2. #import <gamekit/gamekit.h>
  3. #import <objc/objc-runtime.h>
  4.  
  5. @implementation GKActorManager
  6.  
  7. - init
  8. {
  9.     id ret = [super init];
  10.     actorHash = [[HashTable alloc] initKeyDesc:"@" valueDesc:"@" capacity:0];
  11.     return ret;
  12. }
  13.  
  14. - listOfActorsOfClass:aClass
  15. {    // get the list of actors for the given class.  If no list yet, make one.
  16.     id list = [actorHash valueForKey:aClass];
  17.     if (!list) {
  18.         list = [[List alloc] init];
  19.         [actorHash insertKey:aClass value:list];
  20.     }
  21.     return list;
  22. }
  23.  
  24. - addDeadActor:anActor
  25. {
  26.     id list = [self listOfActorsOfClass:[anActor class]];
  27.     // I'd use -addObjectIfAbsent: but this is faster.  Don't add an object
  28.     // twice, though, or actors will start behaving _really_ strangely!
  29.     // (Like jumping around, disappearing, or suddenly "starting over")
  30.     [list addObject:anActor];
  31.     return self;
  32. }
  33.  
  34. - getActorOfClass:aClass
  35. {    // list should NEVER be nil!
  36.     id list = [actorHash listOfActorsOfClass:aClass];
  37.     int count = [list count]; //send message once...cache the result
  38.     if (!count) return [[aClass alloc] init];
  39.     // removing from end is fastest
  40.     return [list removeObjectAt:(count-1)];
  41. }
  42.  
  43. - getActorOfClassNamed:(char *)className
  44. {
  45.     [self getActorOfClass:objc_lookUpClass(className)];
  46.     return self;
  47. }
  48.  
  49. @end
  50.